<template>
    <div class="tape clearfix">
        <div class="tape-main">
            <ul class="tape-left">
                <li>
                    <!--放入首页地址即可-->
                    <router-link to="/home" class="tape-left-item1" style="color: red;padding-left:0">首页</router-link>
                </li>

                <li class="tape-left-list1">
                    <a href="javascript:" class="tape-left-item1">
                        <span>好物</span>
                        <i class="iconfont icon-xialajiantouxiao"></i>
                    </a>
                    <ul class="tape-left-addpage">
                        <li>
                            <a href="javascript:">热度商品</a>
                        </li>
                        <li>
                            <a href="javascript:">良心好物</a>
                        </li>
                        <li>
                            <a href="javascript:">白菜价</a>
                        </li>
                    </ul>
                </li>

                <li class="tape-left-list2">
                    <a href="javascript:" class="tape-left-item1">
                        <span>社区</span>
                        <i class="iconfont icon-xialajiantouxiao"></i>
                    </a>
                    <ul class="tape-left-addpage">
                        <li>
                            <a href="javascript:">我的消息</a>
                        </li>
                        <li>
                            <a href="javascript:">好友</a>
                        </li>
                        <li>
                            <a href="javascript:">交易心得</a>
                        </li>
                    </ul>
                </li>
            </ul>

            <ul class="tape-right">
                <li class="tape-right-list1">
                    <a href="javascript:" class="tape-right-item1">
                        <span>联系我们</span>
                        <i class="iconfont icon-xialajiantouxiao"></i>
                    </a>
                    <ul class="tape-right-addpage">
                        <li>QQ:2694382488</li>
                        <li>Tele:17620706997</li>
                    </ul>
                </li>

                <li class="tape-right-list2">
                    <a href="javascript:" class="tape-right-item1">
                        <span>商务合作</span>
                        <i class="iconfont icon-xialajiantouxiao"></i>
                    </a>
                    <ul class="tape-right-addpage">
                        <li>
                            <a href="javascript:">广告投放</a>
                        </li>
                        <li>
                            <a href="javascript:">加入运营</a>
                        </li>
                        <li>
                            <a href="javascript:">我要开店</a>
                        </li>
                    </ul>
                </li>

                <li class="tape-right-list3" v-if="!token">
                    <router-link class="user-login" to="/login">登录</router-link>
                    <i class="iconfont icon-fengexian"></i>
                    <router-link class="user-login" to="/register">注册</router-link>
                </li>

                <li class="tape-right-list3" v-else>
                    <span class="user">
                        <router-link to="/userspace" class="user-name">
                            <span class="name">{{ userName }}</span>
                            <i class="iconfont icon-xialajiantouxiao"></i>
                        </router-link>
                        <div class="menu-wrapper" ref="menu">
                            <ul>
                                <li>
                                    <router-link to="/userspace">个人中心</router-link>
                                </li>
                                <li>
                                    <router-link to="/shopcart">我的购物车</router-link>
                                </li>
                                <li>
                                    <router-link to="/userspace/mytrade">我的订单</router-link>
                                </li>
                                <li>
                                    <a>我的喜欢</a>
                                </li>
                                <li>
                                    <a @click="userLogout">退出登录</a>
                                </li>
                            </ul>
                        </div>
                    </span>
                    <i class="iconfont icon-fengexian"></i>
                    <a class="user-login" @click="userLogout">退出登录</a>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
export default {
    computed: {
        ...mapState("user", ["token"]),
        ...mapGetters("user", ["userName"]),
    },
    methods: {
        async userLogout() {
            this.$store.dispatch("user/userLogout");
            this.$message({
                message: "退出成功",
                type: "success",
            });
        },
    },
};
</script>

<style lang="less" scoped>
/*以下部分是给头部粘滞条编辑样式*/
.tape {
    width: 100%;
    height: 40px;
    background-color: #fff;
    z-index: 99;
    position: sticky;
    top: 0;
}

.tape a {
    text-decoration: none;
    color: #333333;
}

.tape .tape-main {
    width: 1200px;
    height: 40px;
    margin: 0 auto;
}

.tape .tape-main .tape-left {
    float: left;
}

.tape .tape-main .tape-left > li {
    float: left;
    margin-left: 9px;
}

.tape .tape-main .tape-left li .tape-left-item1 {
    height: 40px;
    font: bold 17px/40px PingFangSC-Medium, arial, sans-serif;
    display: block;
    border: 1px solid #fff;
    border-bottom: none;
    border-top: none;
    margin-top: -2px;
    padding: 0 30px;
}

.tape .tape-main .tape-left li a i {
    margin-left: 8px;
}

.tape .tape-main .tape-left li .tape-left-addpage {
    height: 0px;
    overflow: hidden;
    transition: height 0.3s;

    border: 1px solid transparent;
    border-top: none;
    background-color: #fff;
    margin-top: -2px;
    position: absolute;
}

.tape .tape-main .tape-left li .tape-left-addpage a {
    height: 40px;
    font: 14px/40px PingFangSC-Medium, arial, sans-serif;
    display: block;
    padding: 0 31px;
    text-align: center;
}

.tape .tape-main .tape-left li .tape-left-addpage li:last-of-type {
    margin-bottom: 5px;
}

.tape .tape-main .tape-left .tape-left-list1:hover .tape-left-addpage,
.tape .tape-main .tape-left .tape-left-list1:hover .tape-left-item1 {
    border: 1px solid rgb(204, 204, 204);
    border-top: none;
    box-shadow: 0 10px 10px rgb(204, 204, 204);
    z-index: 99;
}

.tape .tape-main .tape-left .tape-left-list1:hover .tape-left-addpage {
    height: 125px;
}

.tape .tape-main .tape-left .tape-left-list1:hover .tape-left-addpage a:hover {
    color: red;
    background-color: rgb(255, 236, 236);
}

.tape .tape-main .tape-left .tape-left-list1:hover .tape-left-item1 {
    color: red;
    border-bottom: none;
}

.tape .tape-main .tape-left .tape-left-list2:hover .tape-left-addpage,
.tape .tape-main .tape-left .tape-left-list2:hover .tape-left-item1 {
    border: 1px solid rgb(204, 204, 204);
    border-top: none;
    box-shadow: 0 10px 10px rgb(204, 204, 204);
    z-index: 99;
}

.tape .tape-main .tape-left .tape-left-list2:hover .tape-left-addpage {
    height: 125px;
}

.tape .tape-main .tape-left .tape-left-list2:hover .tape-left-addpage a:hover {
    color: red;
    background-color: rgb(255, 236, 236);
}

.tape .tape-main .tape-left .tape-left-list2:hover .tape-left-item1 {
    color: red;
    border-bottom: none;
}

.tape .tape-main .tape-right {
    float: right;
    position: relative;
}

.tape .tape-main .tape-right > li {
    float: left;
    margin-right: 9px;
}

.tape .tape-main .tape-right li .tape-right-item1 {
    height: 38px;
    line-height: 38px;
    display: block;
    padding: 0 30px;
    margin-top: -2px;
    border: 1px solid #fff;
    border-bottom: none;
    border-top: none;
}

.tape .tape-main .tape-right .tape-right-list3 {
    height: 38px;
    line-height: 38px;
    margin-top: -2px;
    padding: 0 15px 0 30px;
    width:240px;
    display: flex;
    justify-content: right;

    .user {
        float: left;
        width: 115px;
        text-align: center;
        height: 40px;
        position: relative;

        .user-name {
            display: block;
            width: 115px;
            height: 40px;
            line-height: 40px;
            font-size: 13px;
            z-index: 21;
            position: relative;
            background-color: white;

            .name {
                margin-right: 10px;
            }

            i {
                font-size: 13px;
            }
        }

        .menu-wrapper {
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
            background-color: white;
            overflow: hidden;
            transition: all 0.3s;
            height: 0;
            position: relative;
            z-index: 20;

            ul {
                padding: 7px 0;
                li {
                    a {
                        height: 30px;
                        line-height: 30px;
                        display: block;
                        font-size: 12px;
                        cursor: pointer;
                    }

                    a:hover {
                        background: rgb(245, 245, 245);
                    }
                }
            }
        }
    }

    .user:hover {
        .menu-wrapper {
            height: 164px;
        }
        a:hover {
            color: rgb(255, 106, 0);
        }
    }
}

.tape .tape-main .tape-right li .tape-right-addpage {
    height: 0px;
    overflow: hidden;
    transition: height 0.3s;
    width: 148px;
    border: 1px solid transparent;
    border-top: none;
    background-color: #fff;
    position: absolute;
}

.tape .tape-main .tape-right .tape-right-addpage > li {
    width: 148px;
    height: 40px;
    font: 14px/40px PingFangSC-Medium, arial, sans-serif;
    text-align: center;
}

.tape .tape-main .tape-right .tape-right-addpage a {
    height: 40px;
    font: 14px/40px PingFangSC-Medium, arial, sans-serif;
    display: block;
    padding: 0 30px;
    text-align: center;
}

.tape .tape-main .tape-right .tape-right-addpage li:last-of-type {
    margin-bottom: 5px;
}

.tape .tape-main .tape-right .tape-right-list1:hover .tape-right-addpage,
.tape .tape-main .tape-right .tape-right-list1:hover a {
    border: 1px solid rgb(204, 204, 204);
    border-top: none;
    box-shadow: 0 10px 10px rgb(204, 204, 204);
    z-index: 99;
}

.tape .tape-main .tape-right .tape-right-list1:hover .tape-right-addpage {
    height: 86px;
}

.tape .tape-main .tape-right .tape-right-list1:hover .tape-right-item1 {
    color: red;
    border-bottom: none;
}

.tape .tape-main .tape-right .tape-right-list2:hover .tape-right-item1,
.tape .tape-main .tape-right .tape-right-list2:hover .tape-right-addpage {
    color: red;
    border: 1px solid rgb(204, 204, 204);
    border-top: none;
    border-bottom: none;
    box-shadow: 0 10px 10px rgb(204, 204, 204);
    z-index: 99;
}

.tape .tape-main .tape-right .tape-right-list2:hover .tape-right-addpage {
    height: 125px;
}

.tape
    .tape-main
    .tape-right
    .tape-right-list2:hover
    .tape-right-addpage
    li:hover
    a {
    color: red;
    background-color: rgb(255, 236, 236);
}

.tape .tape-main .tape-right li a i {
    margin-left: 8px;
}

/*设置登录与注册按键被选中时的效果*/
.tape .tape-main .tape-right li .user-login:hover {
    color: red;
}

a{
    cursor: pointer;
}
</style>
